
<div class="container">
    <div class='_main_'>
<link href="http://cdn.bootcss.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
<link href="/public/css/main.css" rel="stylesheet">
<script type='text/javascript' src='/public/js/jquery-1.11.2.min.js'></script>
<script type="text/javascript" src='/public/js/jquery.validate.js'></script>
<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div  style='height:1.5rem'></div>
<div class='_cut2' ></div>
        <div id="form">
    <?php if(!is_array($data)){ echo "<div style='text-align:center;' >".$data."</div>";exit;} foreach($data as $k=>$v){ if($v['id']=='' ){ continue; } for($i=0;$i<count($v['_items']);$i++){ if($v['_items'][$i]['type'] == $type && $v['order_number']==$order_number || !isset($v['_items'][$i]['type']) ){ continue; }  ?>
    <div class='row'>
        <span style='float:left;'></span>
        <div class='thumbnail' style="float:left;">
            <div style="height:8rem;width:8rem;overflow: hidden;">
                <a href="<?php if($v['team_number']){ echo shop_buildUrl('/user/action/info?aid='.$v['action_id'].'&team_number='.$v['team_number'].'&status=2'); }else{ echo shop_buildUrl('/user/shop/info?item_id='.$v['_items'][$i]['item_id']); } ?>" >
                <img class='_img' src="<?php  echo 'http://'.IMAGE_DOMAIN_.$v['_items'][$i]['item']['images'][0]['image'] ;?>" style='width:100%;height:100%'/></a>
            </div>
        </div>
        <div>
            <div  style='font-size:1.2rem;margin-top:1rem;' ><?php echo $v['_items'][$i]['item']['name'];?></div>
            <div class='_line'></div>
            <div ><i><font style='color:red;font-size:1.7rem'>￥<?php echo $v['_items'][$i]['item']['price']/100;?></font></i>
            </div>
            <div style='float:right;overflow:hidden;color:red'>
              已使用
            </div>
        </div>
        <div class='_line' style='height:1rem;' ></div>
        <span  >
            <a data-toggle="collapse"  class="nav-header" style='color:black;'  data-parent="#accordion" href="#collapse<?php echo $k.'-'.$i; ?>">订单详情</a>                                        
        </span>

        <div id="collapse<?php echo $k.'-'.$i; ?>" class="panel-collapse collapse " style='background-color:#dddddd;margin-top:1rem;' >
            <div class="panel-body"  >
                  <div class='caption'>
                <div>
                <div><?php if($v['team_number']){  ?>
                    <b><span style="font-size:2rem;color:#6495ED">活动：</span></b>
                    <?php }else{?>
                    <b><span style="font-size:2rem;color:#6495ED">商城：</span></b>
                    <?php   }?>
                </div>
                <div>
                    <span>订单号：<?php echo $v['order_number'];?></span>
                </div>
                <div>
                    <span>手机号：<?php echo $v['mobile'];?></span>
                </div>
                <div>
                    <span>下单时间：<?php echo date('Y-m-d H:i:s',$v['create_time']);?></span>
                </div>
                <div>
                    <div>项目：</div>
                    <?php if($v['_items'][$i]['type']!=0){  ?>
                        <?php  foreach($v['_items'][$i]['item']['items'] as $kk=>$vv){ $item_name=$vv['name'];  ?>
                         <span style='margin-left:2rem;' > <?php echo $item_name.'&nbsp;&nbsp;&nbsp;&nbsp;'.$v['_items'][$i+$kk]['count'].'&nbsp;&nbsp;个/次<br>'; ?> </span>
                   <?php }}else{  ?>
                        <span style='margin-left:2rem;' > <?php echo  $v['_items'][$i]['item']['name'].'&nbsp;&nbsp;&nbsp;&nbsp;'.$v['_items'][$i]['count'].'&nbsp;&nbsp;个/次<br>'; ?> </span>
                   <?php  } ?>
                </div>
                <div>
                    <span>门店：<?php echo $stores[$v['store_id']];?></span>
                </div>
                <div>
                    <span>订单状态：已使用</span>
                </div>
                <div>
                    <span>类型：<?php if($v['team_number']){   echo $v['_items']['orders']['my'];}else{ echo '商城订单'; }?></span>&nbsp;&nbsp;
                    <?php if($v['team_number']){ ?>
                    <span style="color:#CD5C5C">人数：<?php echo $v['_items']['orders']['people_num'];?></span>&nbsp;&nbsp;
                    <?php  if($v['_items']['orders']['_status']!=''){?>
                    <span style="color:#CD5C5C">状态：<?php echo $v['_items']['orders']['_status'];?></span>
                    <?php } ?>
                    <?php $i++; } ?>
                </div>
                </div>
            </div>
                  
            </div>
        </div> 


    </div>
    <?php $type=$v['_items'][$i]['type']; $order_number=$v['order_number']; } }?>
        </div>


<div class='_line'></div>
<div class='_line'></div>
        <input type="hidden" value="<?php echo $status;?>" id="page_status" >
        <input type="hidden" value='<?php print_r(json_encode($stores));?>' id="page_stores" >


</body></html>
<script type="text/javascript">
    $(document).ready(function(){

        var number = 12;
        var page_status = $('#page_status').val();
        var page_stores = eval('('+ $("#page_stores").val() +')');
        var last_type = '';
        var last_order_number = "";


        $('#pay').click(function(){
            store_id = $('#store_id').val();
            price = $('#price').val();
            order_number = $('#order_number').val();
            window.location.href = "<?php echo shop_buildUrl('/user/shop/pay?store_id="+store_id+"&price="+price+"&order_number="+order_number+"') ?>";
        });




        $(window).scroll(function () {
            loaddata();
        });
        function loaddata() {
            if (number == -1) {
                return;
            }
//            console.log( page_status );
            totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());
            if ($(document).height() <= totalheight) {
                store_id = $('#store_id').val();
                $.ajax({
                    url: "<?php echo shop_buildUrl('/user/shop/append?status="+ page_status +"&start=" + number + "') ?>",
                    async: true,
                    success: function (msg) {
                        if ( msg == 'false') {
                            number = -1;
                            return;
                        }
                        var html = "";
                        msg = eval('(' + msg + ')');
//                        console.log( msg );
                        $.each( msg, function ( k, v ) {

                            if ( v.id == "" ){
                                return;
                            }
                            for ( var i = 0; i < v._items.length; i++ ){
                                if ( v._items[i].type == last_type && v.order_number == last_order_number || v._items[i].type == "undefined" ){
                                    return;
                                }
                                html += '<div class="row">';
                                html += '<span style="float: left;"></span>';

                                html += '<div class="thumbnail" style="float:left;">';
                                html += '<div style="height:8rem;width:8rem;overflow: hidden;">';
                                if ( v.team_number ) { 
                                    f_url = '<?php echo shop_buildUrl("/user/action/info?aid='+v.action_id+'&team_number='+v.team_number+'"); ?>'; 
                                }else{ 
                                    f_url = '<?php echo shop_buildUrl("/user/shop/info?item_id='+v._items[i].item_id+'"); ?>'; 
                                } 
                                html += '<a href="'+ f_url +'">';
                                html += '<img class="_img" src="http://'+ '<?php echo IMAGE_DOMAIN_; ?>'+ v._items[i].item.images[0].image+'" style="width: 100%; height: 100%;">';
                                html += '</a>';
                                html += '</div>';
                                html += '</div>';


                                html += '<div>';
                                html += '<div style="font-size: 1.2rem;margin-top: 1rem">' + v._items[i].item.name + '</div>';
                                html += '<div class="_line"></div>';
                                html += '<div>';
                                html += '<i><font style="color: red;font-size:1.7rem">￥'+ v._items[i].item.price/100 + '</font></i>';
                                html += '</div>';
                                html += '<div style="float: right; overflow: hidden;color: red;" >已使用</div>';
                                html += '</div>';


                                html += '<div class="_line" style="height: 1rem;"></div>';
                                html += '<span><a data-toggle="collapse" class="nav-header" style="color: black;" data-parent="#accordion" href="#collapse'+k+'-'+i+'-'+ v.order_number +'">订单详情</a></span>';

                                html += '<div id="collapse'+k+'-'+i+'-'+ v.order_number +'" class="panel-collapse collapse" style="background-color:#dddddd; margin-top: 1rem;">';
                                html += '<div class="panel-body">';
                                html += '<div class="caption">';
                                html += '<div>';
                                html += '<div>';
                                if ( v.team_number ){
                                    html += '<b><span style="font-size: 2rem;color: #6495ED;">活动：</span></b>';
                                }else{
                                    html += '<b><span style="font-size: 2rem;color: #6495ED;">商城：</span></b>';
                                }
                                html += '</div>';
                                html += '<div><span>订单号：'+ v.order_number +'</span></div>';
                                html += '<div><span>手机号：'+ v.mobile +'</span></div>';
                                html += '<div><span>下单时间：'+ unix_to_datetime( v.create_time )+'</span></div>';
                                html += '<div><div>项目：</div>';
                                if ( v._items[i].type != 0 ){
                                    $.each( v._items[i].item.items, function( kk ,vv ){
                                        html += '<span style="margin-left: 2rem;">'+ vv.name +'&nbsp;&nbsp;&nbsp;&nbsp;'+ v._items[i+kk].count +'&nbsp;&nbsp;个/次<br></span>';
                                    });
                                }else{
                                    html += '<span style="margin-left: 2rem;">'+ v._items[i].item.name +'&nbsp;&nbsp;&nbsp;&nbsp;'+ v._items[i].count +'&nbsp;&nbsp;个/次<br></span>';
                                }
                                html += '</div>';
                                html += '<div><span>门店：'+ page_stores[v.store_id] + '</span></div>';
                                html += '<div><span>订单状态：已使用</span></div>';
                                html += '<div><span>类型：';
                                if ( v.team_number ){
                                    html += v._items.orders.my;
                                }else{
                                    html += '商城订单';
                                }
                                html += '</span>&nbsp;&nbsp;';
                                if ( v.team_number ){
                                    html += '<span style="color: #CD5C5C">人数：'+ v._items.orders.people_num + '</span>&nbsp;&nbsp;';
                                    if(v._items.orders._status != undefined || v._items.orders._status !=''){
                                        html += '<span style="color: #CD5C5C">状态：'+ v._items.orders._status + '</span>';
                                    }
                                    //html += '<span style="color: #CD5C5C">状态：'+ v._items.orders._status + '</span>';
                                }
                                html += '</div>';
                                html += '</div>';
                                html += '</div>';
                                html += '</div>';
                                html += '</div>';

                                html += '</div>';

                                last_type = v._items[i].type;
                                last_order_number = v.order_number;
                            }
                            number += 1;
                        });
                        $('#form').append( html );
                    }
                });
            }
        }
        ////////////////////////////////////////////////////////////////////

        function unix_to_datetime(unix) {
            var now = new Date(parseInt(unix) * 1000);
            return now.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
        }



    })

</script>
